package com.wc.alorithm_luogu._前缀和与差分.借教室;

import java.io.*;
import java.util.Arrays;

/**
 * @Author congge
 * @Date 2025/1/10 9:14
 * @description
 * https://www.luogu.com.cn/problem/P1083
 */
public class Main {
    /**
     * 思路：
     * 二分 + 差分
     * 差分 可以知道每天有多少教室被预定
     *
     * 假设有需要修改的订单
     * 那是不是需要修改订单的前面是全部都可以满足的, 但是加上需要修改的订单就无法满足了
     * 那就产生了二分的性质, 所以使用二分来找到前mid个可以满足条件的, 如果全部都可以满足, 那就说明 mid = n;
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 1000010;
    static int[] a = new int[N], l = new int[N], r = new int[N], tot = new int[N];
    static long[] d = new long[N];
    static int n, m;

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        for (int i = 1; i <= n; i++) tot[i] = sc.nextInt();
        for (int i = 1; i <= m; i++) {
            a[i] = sc.nextInt();
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();
        }
        // 检查前mid个是可以满足
        int l = 0, r = m;
        while (l < r) {
            int mid = l + r + 1 >> 1;
            if (check(mid)) l = mid;
            else r = mid - 1;
        }
        if (r == m) out.println(0);
        else out.printf("%d\n%d\n", -1, r + 1);
        out.flush();
    }

    static boolean check(int x) {
        Arrays.fill(d, 1, n + 1, 0);

        for (int i = 1; i <= x; i++) {
            d[l[i]] += a[i];
            d[r[i] + 1] -= a[i];
        }
        for (int i = 1; i <= n; i++) d[i] += d[i - 1];

        for (int i = 1; i <= n; i++) {
            if (d[i] > tot[i]) return false;
        }

        return true;
    }
}

class FastReader {
    StreamTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
        st = new StreamTokenizer(br);
    }

    int nextInt(){
        try {
            st.nextToken();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return (int) st.nval;
    }
}

